import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { InventoryHistory } from './InventoryHistory';

@Entity('brand', { schema: 'blog_back' })
export class Brand {
  @PrimaryGeneratedColumn({ type: 'int', name: 'id', unsigned: true })
  id: number;

  @Column('varchar', { name: 'name', comment: '品牌名称', length: 255 })
  name: string;

  @Column('varchar', {
    name: 'cover_url',
    nullable: true,
    comment: '品牌封面',
    length: 255,
  })
  coverUrl: string | null;

  @Column('int', {
    name: 'market_price',
    nullable: true,
    comment: '市场价',
    unsigned: true,
  })
  marketPrice: number | null;

  @Column('int', {
    name: 'stock',
    comment: '库存',
    unsigned: true,
    default: () => "'0'",
  })
  stock: number;

  @Column('enum', {
    name: 'status',
    comment: '品牌是否有效',
    enum: ['1', '0'],
    default: () => "'1'",
  })
  status: '1' | '0';

  @Column('timestamp', {
    name: 'create_time',
    comment: '创建时间',
    default: () => 'CURRENT_TIMESTAMP',
  })
  createTime: Date;

  @Column('timestamp', {
    name: 'update_time',
    comment: '更新时间',
    default: () => 'CURRENT_TIMESTAMP',
  })
  updateTime: Date;

  @OneToMany(
    () => InventoryHistory,
    (inventoryHistory) => inventoryHistory.brand,
  )
  inventoryHistories: InventoryHistory[];
}
